package com.example.myandroidwork;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Date;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    long time = 0;
    public void onBackPressed() {
        if(time == 0){
            Toast toast = Toast.makeText(this,"点击退出页面",Toast.LENGTH_SHORT);
            toast.show();
            System.out.println(time);
            time = (new Date()).getTime();
        }else{
            long time2 = (new Date()).getTime();
            if(time2-time<=3000){
                finish();
            }
            else{
                time = 0;
                Toast toast = Toast.makeText(MainActivity.this,"再次点击返回页面",Toast.LENGTH_SHORT);
                toast.show();
            }
        }
    }


}